package priv.stones.collections.list;

import java.util.Set;
import java.util.TreeSet;

/**
 * @Author: Stones
 * @Description:
 * @Date: 2017/11/5 16:56
 */
class Person implements  Comparable<Person> {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }




    @Override
    public int compareTo(Person o) {
        int temp=this.age-o.age;
        if (temp == 0) {
            return this.name.compareTo(o.name);
        }
        else {
            return  temp;
        }
    }


}
public class TreeSet2 {

    public static void main(String[] args) {

        Set<Person> data = new TreeSet<Person>();
        data.add(new Person("hulei", 20));
        data.add(new Person("hujinyang", 1));
        data.add(new Person("zule1", 5));
        data.add(new Person("aulei2", 5));
        data.add(new Person("hule3i", 10));
        data.add(new Person("hulei4", 2));
        System.out.println(data);

    }

}
